<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="h" uri="/syzg-html"%>
<% 
	String ctx = request.getContextPath();  
%>
<%
	/**
	* @author wanglei@enersun.com.cn
	* 该页面提供给其他页面进行访问。
	* 调用方法如下：
	* 1：在调用页面增加一个DIV，用于加载页面<div id="treeDlg"></div>
	* 2：在调用页面增加下列JS代码
		var treeBasicDataViewUrl = "${ctx}/path/basicdata/treebasicdata";//树形列表
		function openBasicData(){
			FormFunction.showModal('treeDlg', treeBasicDataViewUrl, 'treeBasicDataViewModal',function(){
				loadBasicDataData("newsType");
			});
		}
		function setBasicDataValue(data){
			$("#newstype").val(data.text);
		}
	* 3：在调用页面增加触发的方法，如下：
		<input type="text" id="newstype" onclick="openBasicData()" name="newstype" class="form-control" />
	*/
 %>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="<%=ctx%>/baseNew/plugins/bootstrap-treeview/bootstrap-treeview.min.js"></script>
<link href="<%=ctx%>/baseNew/plugins/bootstrap-treeview/bootstrap-treeview.min.css" rel="stylesheet" />
</head>
<body>
	<div class="modal fade bs-example-modal-lg" id="treeBasicDataViewModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog modal-lg" role="document" style="width: 400px;height: 400px;">
			<div class="modal-content" style="width: 400px;height: 400px;">
				<div class="modal-header">
					<h4 class="modal-title" id="myModalLabel">基础数据</h4>
				</div>
				<div class="modal-body" id="modalCore" style="width: 400px;height: 280px;">
					<div id="treeBasicData" style="height: 250px;overflow-x:hidden;"></div>
				</div>
				<!-- 页面底部区域，用于放置功能按钮 -->
				<div class="modal-footer">
					<button type="button" class="btn btn-default" onclick="closeBasicDataWindow()">关闭</button>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		/**
		* 关闭当前窗口
		*/
		function closeBasicDataWindow(){
			ModalUtil.hideModal("treeBasicDataViewModal");
		}
		
		/**
		* 加载数据
		* @parem parentCode如果需要获取所有的基础数据，则不传递参数loadBasicDataData()
		*/
		function loadBasicDataData(parentCode) { 
			$.post("<%=ctx%>/path/basicdata/loadtreebasicdata", {"parentCode":parentCode},
				function(result) {
					if (result.state == 'Success') {
						$('#treeBasicData').treeview({
							data : result.content,
							levels : 5,
							nodeIcon:"glyphicon glyphicon-stop",
							onNodeSelected: function(event, data) {
								if(data.top==false){
					 	 			setBasicDataValue(data);
					 	 			closeBasicDataWindow();
					 	 		}else{
					 	 			return;
					 	 		}
					 	 	}
						});
					} else {
						bootbox.alert("<h4>操作失败,原因："+result.content+"</h4>", function() {
							closeBasicDataWindow();
						});
					}
				}
			);
		}
		
		function loadBasicDataData2(parentCode) { 
			$.post("<%=ctx%>/path/basicdata/loadtreebasicdata", {"parentCode":parentCode},
				function(result) {
					if (result.state == 'Success') {
						$('#treeBasicData').treeview({
							data : result.content,
							levels : 5,
							nodeIcon:"glyphicon glyphicon-stop",
							onNodeSelected: function(event, data) {
								if(data.top==false){
					 	 			setBasicDataValue2(data);
					 	 			closeBasicDataWindow();
					 	 		}else{
					 	 			return;
					 	 		}
					 	 	}
						});
					} else {
						bootbox.alert("<h4>操作失败,原因："+result.content+"</h4>", function() {
							closeBasicDataWindow();
						});
					}
				}
			);
		}
	</script>
</body>
</html>